package kr.hkit.androidcomplete02.ch16;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class OrderDialogEx extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch16_dialog);
	}
	
	public void mOnClick(View v){
		final LinearLayout linear = (LinearLayout) View.inflate(this, R.layout.ch16_orderdialog, null);
		
		new AlertDialog.Builder(this)
				.setTitle("주문정보를 입력하세요")
				.setIcon(R.drawable.gang1)
				.setView(linear)
				.setPositiveButton("확인", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						EditText product = (EditText) linear.findViewById(R.id.ch16_order_product);
						EditText number = (EditText) linear.findViewById(R.id.ch16_order_number);
						CheckBox paymethod = (CheckBox) linear.findViewById(R.id.ch16_order_paymethod);
						TextView tv = (TextView) findViewById(R.id.ch16_dialog_tv);
						tv.setText("주문 정보 : " + product.getText() + " 상품 : " + number.getText() + "개" +
									 ( paymethod.isChecked()? ", 착불결제" : "" ));
					}
				})
				.setNegativeButton("취소", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						TextView tv = (TextView) findViewById(R.id.ch16_dialog_tv);
						tv.setText("주문을 취소하였습니다.");
					}
				}).show();
		
	}
}
